package com.client.job.runJob;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.client.job.core.model.MJob;

public class SystemJobs {
	
	private   static Map<String, MJob>  sysJobMap = new ConcurrentHashMap<>();
	
	public static void  initJob(MJob mJob) {
		sysJobMap.put(mJob.getJobName(), mJob);
	}

	public static void  setJob(MJob mJob) {
		sysJobMap.put(mJob.getJobName(), mJob);
	}

	/**
	 * 获取所有运行的Job
	 * @return
	 */
	public static List<MJob> getJobs(){
		return new ArrayList<>(sysJobMap.values());
	}

	/**
	 * 根据ID查询Job
	 * @param jobId
	 * @return
	 */
	public static List<MJob> getJobs(String jobId){
		List<MJob> jobs = new ArrayList<>();
		for (MJob job : sysJobMap.values()) {
			if(job.getJobId() .equals(jobId)){
				jobs.add(job);
			}
		}
		return jobs;
	}

	/**
	 * 根据名称删除Job
	 * @param jobName
	 */
	public static void removeJob(String jobName) {
		sysJobMap.remove(jobName);
	}

	public static MJob getJobByName(String jobName){
		return sysJobMap.get(jobName);
	}

}
